﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace Madrigal.Lib
{
    public enum OSType
    {
        Unknown,
        NT351,
        Windows95,
        WindowsNT,
        Windows98,
        WindowsME,
        Windows2000,
        WindowsXP,
        WindowsServer2003,
        WindowsVista,
        Windows7,
    }

    public static class xUtil
    {
        public int MaxRand = 0x7fff;

        public static CProf gProf;

        public int nMatixTri = 0;
        public static bool bShadowMsgBox = true;
        public Int64 llFreq;
        public Int32 next;
        public char[] szWorkDir = new char[256];
        public char[] szExeDir = new char[256];

        public OSType osVersion = OSType.Unknown;

        public static int nLanguage = -1; // Default is Korean
        public static int nSubLanguage = 0; // Default Sub Language

        // 2nd Password System v15
        public static bool b2ndPassword = false;

        public Int32 xRand()
        {
            next = next * 1103515245 + 12345;
            return next;
        }

        public Int32 xRandom(Int32 min, Int32 max)
        {
            if (max > min)
                return min + xRandom(max - min);
            else
                return min;
        }

        public Int32 xRandom(Int32 num)
        {
            return xRand() % num;
        }

        public float xRandomF(float num)
        {
            Random rand = new Random();
            return ((float)rand.Next() / (float)MaxRand) * (float)num;
            
        }

        public void xSRand(Int32 seed)
        {
            next = seed;
        }

        public void MakeEven(long x)
        {
            x++;
            x &= (~0x01);
        }

        public void SetLanguageInfo(int lang, int sublang)
        {
            nLanguage = lang;
            nSubLanguage = sublang;
        }

        public int GetLanguage()
        {
            return nLanguage;
        }

        public string GetNumberFormatEx(string number)
        {
            string str = string.Empty;
            string[] charString;

            int nLength = number.Length;
            charString = new string[nLength];

            for (int i = nLength - 1; i >= 0; --i)
            {
                str.Insert(0, charString[i]);
                if (((nLength - i) % 3) == 0 && i != 0)
                    str.Insert(0, ",");
            }

            return str;
        }

        // This gets

        public string GetCPUInfo()
        {
            OperatingSystem os = Environment.OSVersion;

        }

        // This sets whether or not to use the 2nd Password
        // system. If set to true then there will be a second
        // password to be stored and used.
        // This was added with version 15

        public bool Use2ndPassword
        {
            get { return b2ndPassword; }
            set { b2ndPassword = value; }
        }
    }
}
